# 基础Linux容器 - 无桌面环境，支持SSH
FROM ubuntu:22.04

# 设置环境变量
ENV DEBIAN_FRONTEND=noninteractive
ENV TZ=Asia/Shanghai

# 更新系统并安装基础软件包
RUN apt-get update && apt-get install -y \
    openssh-server \
    sudo \
    curl \
    wget \
    vim \
    nano \
    git \
    htop \
    tree \
    unzip \
    zip \
    net-tools \
    iputils-ping \
    telnet \
    tzdata \
    locales \
    && rm -rf /var/lib/apt/lists/*

# 配置时区
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

# 配置locale
RUN locale-gen en_US.UTF-8
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8

# 配置SSH
RUN mkdir /var/run/sshd
RUN echo 'root:root123' | chpasswd
RUN sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config
RUN sed -i 's/#PasswordAuthentication yes/PasswordAuthentication yes/' /etc/ssh/sshd_config

# 创建普通用户
RUN useradd -m -s /bin/bash developer && \
    echo 'developer:dev123' | chpasswd && \
    usermod -aG sudo developer

# 配置sudo免密码
RUN echo 'developer ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers

# 创建SSH密钥目录
RUN mkdir -p /home/developer/.ssh && \
    chown developer:developer /home/developer/.ssh && \
    chmod 700 /home/developer/.ssh

# 暴露SSH端口
EXPOSE 22

# 启动脚本
COPY container-start.sh /start.sh
RUN chmod +x /start.sh

# 启动SSH服务
CMD ["/start.sh"]